from datetime import datetime

from django.db import models

# Create your models here.
from shortuuidfield import ShortUUIDField

from user_model.models import ComplainModel

GENDER_CHOICES = (
    (u'0', u'正常'),
    (u'1', u'注销'),
)
GENDER_CHOICES_SEX = (
    (u'0', u'全部'),
    (u'1', u'男'),
    (u'2', u'女'),
)


# 医院名称表
class HospitalModel(models.Model):
    h_id = ShortUUIDField(primary_key=True, verbose_name="医院id")
    h_name = models.CharField(max_length=128, null=False, blank=False, verbose_name="医院名称")

    class Meta:
        db_table = 'hospital_name'
        verbose_name = '医院表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.h_name


# 科室表
class DepartmentModel(models.Model):
    d_id = ShortUUIDField(primary_key=True, verbose_name="科室id")
    d_name = models.CharField(max_length=128, null=False, blank=False, verbose_name="科室名称")
    d_status = models.CharField(max_length=2, choices=GENDER_CHOICES, default='0', verbose_name="是否删除科室")
    d_key = models.ManyToManyField(HospitalModel, related_name='hospital', verbose_name="关联")

    class Meta:
        db_table = 'hospital_department'
        verbose_name = '科室表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.d_name


# 预约时间点表
class TimeModel(models.Model):
    t_id = ShortUUIDField(primary_key=True, verbose_name="时间表id")
    t_name = models.CharField(max_length=32, verbose_name='简写')
    t_number = models.CharField(max_length=6, verbose_name="预约人数")
    t_start_time = models.TimeField(max_length=128, verbose_name="开始时间")
    t_end_time = models.TimeField(max_length=128, verbose_name="结束时间")
    t_status = models.CharField(max_length=2, choices=GENDER_CHOICES, default='0', verbose_name="是否删除时间")

    class Meta:
        db_table = 'hospital_timing'
        verbose_name = '预约时间点表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.t_name


# 预约日期表
class DataTimeModel(models.Model):
    d_id = ShortUUIDField(primary_key=True, verbose_name="日期表id")
    d_data = models.CharField(max_length=10, verbose_name="预约星期几")
    d_status = models.CharField(max_length=2, choices=GENDER_CHOICES, default='0', verbose_name="是否删除日期")

    class Meta:
        db_table = 'hospital_data'
        verbose_name = '预约日期表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.d_data


# 时间段
class TimeQuantumModel(models.Model):
    t_id = ShortUUIDField(primary_key=True, verbose_name="预约项目表id")
    t_name = models.CharField(max_length=32, verbose_name='简写')
    start_time = models.DateField(auto_now=False, verbose_name="开始日期")
    end_time = models.DateField(auto_now=False, verbose_name="结束日期")
    d_key = models.ManyToManyField(DataTimeModel, related_name='time', verbose_name='预约日期表')
    d_time = models.ManyToManyField(TimeModel, related_name='datetime', verbose_name='预约时间点')

    class Meta:
        db_table = 'hospital_paragraph'
        verbose_name = '预约时间段'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.t_name


# 检查项目表
class ProjectModel(models.Model):
    p_id = ShortUUIDField(primary_key=True, verbose_name="预约项目表id")
    p_name = models.CharField(max_length=128, verbose_name="检查项目")
    p_money = models.CharField(max_length=32, verbose_name="检查费用")
    p_prepay = models.CharField(max_length=32, verbose_name="预交费")
    p_note = models.TextField(verbose_name="注意事项", null=True)
    p_day = models.CharField(max_length=3, verbose_name="提前预约天数")
    p_number = models.CharField(max_length=3, verbose_name="预约次数")
    free_number = models.CharField(max_length=3, default=0, verbose_name="免费次数")
    cancel_time = models.CharField(max_length=3, verbose_name='提前取消时间')
    start_age = models.CharField(default=0, max_length=6, verbose_name='开始年龄')
    end_age = models.CharField(default=200, max_length=6, verbose_name='结束年龄')
    c_sex = models.CharField(max_length=2, choices=GENDER_CHOICES_SEX, default='0', verbose_name="性别")
    p_status = models.CharField(max_length=2, choices=GENDER_CHOICES, default='0', verbose_name="是否删除检查项目")
    p_key = models.ManyToManyField(DepartmentModel, related_name='department', verbose_name="关联科室")
    p_key_time = models.ManyToManyField(TimeQuantumModel, related_name='project', verbose_name='预约时间段')

    class Meta:
        db_table = 'hospital_project'
        verbose_name = '检查项目表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.p_name


# 投诉回复表
class ReplyModel(models.Model):
    r_id = ShortUUIDField(primary_key=True, verbose_name="投诉回复id")
    r_content = models.TextField(verbose_name="投诉回复内容")
    r_time = models.DateTimeField(default=datetime.now, verbose_name="回复时间")

    class Meta:
        db_table = 'hospital_reply'
        verbose_name = '投诉回复表'
        verbose_name_plural = verbose_name


# 协议表
class AgreementModel(models.Model):
    a_id = ShortUUIDField(primary_key=True, verbose_name="协议id")
    a_content = models.TextField(verbose_name="协议内容")
    a_time = models.CharField(default=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), max_length=20,
                              verbose_name="协议生成日期")
    a_status = models.CharField(max_length=2, choices=GENDER_CHOICES, default='0', verbose_name="是否删除")

    class Meta:
        db_table = 'hospital_agreement'
        verbose_name = '协议表'
        verbose_name_plural = verbose_name

# 年龄表
# class AgeModel(models.Model):
#     c_id = ShortUUIDField(primary_key=True, verbose_name="预约项目表id")
#     a_name = models.CharField(max_length=32, verbose_name='简写')
#     start_age = models.CharField(default=0, max_length=6, verbose_name='开始年龄')
#     end_age = models.CharField(default=200, max_length=6, verbose_name='结束年龄')
#
#     class Meta:
#         db_table = 'hospital_age'
#         verbose_name = '年龄表'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return self.a_name
# 受众人群
# class CrowdModel(models.Model):
#
#
#     c_id = ShortUUIDField(primary_key=True, verbose_name="预约项目表id")
#     c_name = models.CharField(max_length=32, verbose_name='简写')
#     c_sex = models.CharField(max_length=2, choices=GENDER_CHOICES_SEX, default='0', verbose_name="性别")
#     c_key = models.ManyToManyField(AgeModel, related_name='age', verbose_name="关联年龄表")
#
#     # p_key = models.ManyToManyField(DepartmentModel, related_name='department', verbose_name="关联")
#     class Meta:
#         db_table = 'hospital_crowd'
#         verbose_name = '受众人群表'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return self.c_name
